<?php

namespace wechat\models;

use yii\base\Behavior;
use yii\helpers\Json;

use EasyWeChat\Message\Text;
use EasyWeChat\Message\Image;
use EasyWeChat\Message\Voice;
use EasyWeChat\Message\News;
use EasyWeChat\Message\Article;

class EchoBehavior extends Behavior {
    public function events() {
        return [
            Wechat::EVENT_MSG_TEXT => 'echoWechat',
            Wechat::EVENT_MSG_IMAGE => 'echoWechat',
        ];
    }
    
    public function echoWechat($event) {
        $owner = $this->owner;
        $owner->response = $owner->getRequest();
        $owner->response['FromUserName'] = $owner->getRequest('ToUserName');
        $owner->response['ToUserName'] = $owner->getRequest('FromUserName');
        $owner->response['CreateTime'] = time();
        $owner->response['Content'] = "亲爱的{$owner->wxUser->nickname},".$owner->response['Content'];
    }
}
